package dead;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class TestJson {
	private String url = "http://www.prism.gatech.edu/~dcarlan3/appathon/formation.php";
	
	public void executeJson() {
		HttpClient client = new DefaultHttpClient();
		url = String.format("%s?group=%s", url, "poop");
		Log.i("url", url);
		url = String.format("%s?group=%s", url, "poop");
		HttpGet get = new HttpGet(url);
		HttpResponse response;
		try {
			Log.i("tits", "executing get");
			response = client.execute(get);
			Log.i("tits", "get status line");
			StatusLine statusLine = response.getStatusLine();
			Log.e("tits", "get status code");
		      int statusCode = statusLine.getStatusCode();
		      if (statusCode == 200) {
		    	  Log.e("tits", "status code = 200");
		    	  Log.e("tits", "get entity");
		    	  HttpEntity entity = response.getEntity();
		    	  Log.e("tits", "get entity");
		          InputStream content = entity.getContent();
		          Log.e("tits", "new string builder");
		          StringBuilder builder = new StringBuilder();
		          Log.e("tits", "new buffered reader");
		          BufferedReader reader = new BufferedReader(new InputStreamReader(content));
		          String line;
		          while ((line = reader.readLine()) != null) {
		        	  builder.append(line);
		          }
		          Log.e("tits", "content close");
		          content.close();
		          if (builder.toString() == null) {
		        	  Log.e("screven", "builder is null");
		          }
		          else {
		        	  Log.e("SCREVEN", builder.toString());
		          }
		          JSONObject obj = new JSONObject(builder.toString());
		          if (obj.toString() == null) {
		        	  Log.e("screven", "object is null");
		          }
		          else {
		        	  Log.e("SCREVEN", obj.toString());
		          }
		      }
		      else {
		    	  Log.e("SCREVEN", "Bad connection to php");
		      }
		}
		catch (Exception e) {
			//Log.e("SCREVEN", e.getMessage());
			Log.e("tits", "exception");
			e.printStackTrace();
		}
	}
}
